package com.goldsprite.infinityworld.screens.games;

import com.badlogic.gdx.scenes.scene2d.ui.*;
import com.badlogic.gdx.utils.viewport.*;

import com.badlogic.gdx.utils.ScreenUtils;
import com.goldsprite.gdxcore.entities.GameWorldGroup;
import com.goldsprite.gdxcore.screens.GScreen;
import com.goldsprite.gdxcore.ui.GStage;
import com.goldsprite.infinityworld.assets.GlobalAssets;
import com.goldsprite.infinityworld.entities.gameworlds.InfinityGameWorld;
import com.goldsprite.infinityworld.ui.EditorLayout;

public class EngineEditorScreen extends GScreen {
	private GStage stage;
	private Skin skin;

	//游戏世界
	private InfinityGameWorld world;

	private WidgetGroup gameTable;

	private FitViewport viewport;

	public static float screenWidthRatio, editorWidth, editorHeight;

	private EditorLayout editorLayout;

	@Override
	public Viewport getViewport() {
		return viewport;
	}


	@Override
	public void create() {
		skin = GlobalAssets.getInstance().editorSkin;
		
		editorWidth = 960;
		editorHeight = 540;
		screenWidthRatio = editorWidth/editorHeight;

		viewport = new FitViewport(editorWidth, editorHeight);
		viewport.apply(true);
		stage = new GStage(viewport);
		getImp().addProcessor(stage);

		// 游戏视图区域
		gameTable = new WidgetGroup();
		//游戏世界Group
		GameWorldGroup gameCanvasGroup = new GameWorldGroup();
		gameCanvasGroup.setScreenCam(stage.getCamera());
		gameCanvasGroup.setScreen(this);
		gameTable.addActor(gameCanvasGroup);

		world = new InfinityGameWorld();
		
		editorLayout = new EditorLayout();
		editorLayout.init(this, skin, gameTable, ()->{
			if (!world.gameInitialized) {
				world.initGameWorld(skin, gameCanvasGroup);
			}
		});


		stage.addActor(editorLayout);
	}
	

	@Override
	public void render(float delta) {
		ScreenUtils.clear(0.35f, 0.35f, 0.35f, 1);
		
		stage.act(delta);
		stage.draw();
	}

}

